package pl.wroc.uni.ii.evolution.engine.operators.spacespecific.binaryvector;

import pl.wroc.uni.ii.evolution.engine.EvPopulation;
import pl.wroc.uni.ii.evolution.engine.individuals.EvBinaryVectorIndividual;
import pl.wroc.uni.ii.evolution.engine.prototype.EvOperator;
import pl.wroc.uni.ii.evolution.engine.operators.spacespecific.binaryvector.sboa.*;

public class EvBinaryVectorSBoaOperator implements EvOperator<EvBinaryVectorIndividual> {

  private int number_of_variables;
  private int children_size;
  private int k;
  
 
  public EvBinaryVectorSBoaOperator(int number_of_variables, int k, int children_size) {
    this.number_of_variables = number_of_variables;
    this.children_size = children_size;
    this.k = k;
  }
  
  public EvPopulation<EvBinaryVectorIndividual> apply(EvPopulation<EvBinaryVectorIndividual> population) {
    
    EvBayesianNetwork network = new EvBayesianNetwork(number_of_variables, k);   
    EvBoaStrategy strategy = new EvBoaStrategy();
    
    strategy.init(population.size() + 1, k);
    strategy.model2(population, network);
    
    EvBinaryVectorIndividual[] pop = population.toArray(new EvBinaryVectorIndividual[population.size()]);
    
    EvPopulation<EvBinaryVectorIndividual> result = new EvPopulation<EvBinaryVectorIndividual>();
    
    for (int i = 0; i < children_size; i++) {
      result.add(network.generate(pop));
    }
    
    return result;
  }

  
  
}
